<template>
    <div>
        <table>
            <tbody>
                <tr>
                    <td>名称</td>
                    <td>
                        <input type="text" v-model="date.houseName">
                    </td>
                </tr>
                <tr>
                    <td>图片</td>
                    <td>
                        <input type="file" @change="upload">
                        <img :src="'https://localhost:7021/'+date.img" width="100px" height="100px">
                    </td>
                </tr>
                <tr>
                    <td>状态名称</td>
                    <td>
                        <select v-model="date.houseTypeId">
                            <option value="0">请选择</option>
                            <option value="1">大床房</option>
                            <option value="2">经济房</option>
                            <option value="3">总统套房</option>
                        </select>
                    </td>
                </tr>
                <tr>
                    <td>状态</td>
                    <td>
                        <input type="checkbox" v-model="date.iState">勾为true
                    </td>
                </tr>
                <tr>
                    <td colspan="2">
                        <input type="button" value="添加" @click="update">
                    </td>
                </tr>
            </tbody>
        </table>
    </div>
</template>

<script setup lang="ts">
import axios from 'axios'
import { idText } from 'typescript';
import { ref,onMounted } from 'vue';
import { useRouter,useRoute } from 'vue-router';
const routher = useRouter();
const routhe = useRoute();
onMounted(()=>{
    upd()
})
const upd=()=>{
    var vid = routhe.query.id;
    axios.get("https://localhost:7021/api/House/GetHouse",{params:{id:vid}}).then(res=>{
        date.value=res.data;
    }) 
}

const update=()=>{
    axios.post("https://localhost:7021/api/House/UpHouse",date.value).then(res=>{
        if(res.data>0){
            alert("更新成功")
            routher.push({path:"/Show"})
        }
        else{
            alert("更新失败")
        }
    })
}
const date=ref({
  "houseId": 0,
  "houseName": "",
  "img": "",
  "houseTypeId": 0,
  "iState": false
})
const upload=(e:any)=>{
    var a = e.target.files[0]
    var aa = new FormData()
    aa.append("file",a)

    axios.post("https://localhost:7021/api/Upload/UpFile",aa).then(res=>{
        date.value.img=res.data;
        alert("上传成功")
    })
}
</script>

<style scoped>

</style>